<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <p>loading</p>
</body>
<script>
    //https://api.github.com/search/repositories?q=js&sort=stars&order=desc
    //创建一个请求对象
    var xhr = new XMLHttpRequest();
    //为异步请求注册注册回调
    xhr.onreadystatechange=()=>{
        if(xhr.readyState === 4){
            if(xhr.status===200 || xhr.status===304 ){
                var response = JSON.parse(xhr.responseText);
                var p = document.querySelector("p");
                p.style.display="none";
                var divNode = document.createElement("div");
                divNode.innerHTML=`github上最流行的库是<a href="${response.items[0].html_url}">${response.items[0].name}</a>`
                document.body.appendChild(divNode)
            }else {
                console.log("请求失败")
            }
        }
    }
    //初始化请求
    xhr.open("get","https://api.github.com/search/repositories?q=js&sort=stars&order=desc");
    //发送请求
    xhr.send();
</script>
</html>